const fs = require('fs');
const path = require('path');
const JavaScriptObfuscator = require('javascript-obfuscator');
const config = require('./exe.config');

const BUILD_PATH = './out/renderer/assets';





const mkdirs = (dirpath) => {
    if (!fs.existsSync(path.dirname(dirpath))) {
        mkdirs(path.dirname(dirpath));
    }
    fs.mkdirSync(dirpath);
}
const copys = (dir) => {
    var files = fs.readdirSync(dir);
    for (let item of files) {
        const o = `${dir}/${item}`;
        var stats = fs.statSync(o);
        if (stats.isDirectory()) {
            copys(o)
        } else {
            if (path.parse(o).ext == '.js'  && o.indexOf('node-') == -1) {
                const content = fs.readFileSync(o).toString();
                const obfuscationResult = JavaScriptObfuscator.obfuscate(content, config);
                const code = obfuscationResult.getObfuscatedCode();
                fs.writeFileSync(o, code);
            } 


        }
    }
}


copys(BUILD_PATH);




